<?php
/**
 * Defines patterns class for parser.
 *
 * @package    blocks
 * @copyright &copy; 2011 Sergey Pashaev, Volgograd State Technical University
 * @license    http://www.gnu.org/copyleft/gpl.html GNU Public License
 */

class block_formal_langs_parser_grammar {
    /**
     * Start terminal.
     * @var string - name of start nonterminal.
     */
    public $start;

    /**
     * Array of tokens from lexer.
     * @var aray of base_token or it child classes.
     */
    public $terminals;

    /**
     * List of grammar rules.
     * @var array of objects of parser_rule.
     */
    public $rules;
}

/**
 * Class for parser patterns.
 *
 * Class for storing patterns.
 *
 * @copyright  &copy; 2011 Sergey Pashaev, Volgograd State Technical University
 * @license    http://www.gnu.org/copyleft/gpl.html GNU Public License 
 */

class block_formal_langs_parser_rule {
    /**
     * Pattern name.
     * @var string
     */
    private $name;

    /**
     * Terminal description string.
     * @var string
     */
    private $desc;

    /**
     * List of alternatives. "Right part" of rule.
     * @var list of rule_alternative objects.
     */
    private $alternatives;

    /**
     * Left part options.
     * @var array of options objects.
     */
    private $options;

    public function __construct($name,
                                $alternatives,
                                $desc = '',
                                $options = null) {
        $this->name = $name;
        $this->desc = $desc;
        $this->alternatives = $alternatives;
        $this->options = $options;
    }

    public function name() {
        return $this->name;
    }

    public function alternatives(){
        return $this->alternatives;
    }
}

class block_formal_langs_parser_option {
    private $name; // string
    private $args; // array of strings.

    public function __construct($name, $args = null) {
        $this->name = $name;
        $this->args = $args;
    }
}

class block_formal_langs_parser_rule_alternative {
    private $num; // number of alternative
    private $rule_num; // number of rule that contains this alternative

    /**
     * Left part of rule terminal description.
     * @var string
     */
    private $desc;

    /**
     * Pattern name.
     * @var list of rule_alternative_element objects.
     */
    private $elements;

    private $translations;

    public function __construct($elements,
                                $desc = null,
                                $translations = null) {
        $this->desc = $desc;
        $this->elements = $elements;
        $this->translations = $translations;
        $this->num = -1;
        $this->rule_num = -1;
    }

    public function elements() {
        return $this->elements;
    }

    public function set_num($num) {
        $this->num = $num;
    }

    public function num(){
        return $this->num;
    }

    public function set_rule_num($num) {
        $this->rule_num = $num;
    }
    
    public function rule_num() {
        return $this->rule_num;
    }
}

?>